package com.gage.print.pdf.util;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import com.gage.print.pdf.model.Major;
import com.gage.print.pdf.model.Student;
import com.gage.print.pdf.vo.Result;

public class Constant {
	public static final List<Major> MAJOR_LIST = new ArrayList<Major>();
	public static final Map<String, Major> MAJOR_MAP = new HashMap<String, Major>();
	public static final List<Student> STUDENT_LIST = new ArrayList<Student>();
	public static final List<Result> RESULT_LIST = new ArrayList<Result>();
	private static final int STUDENT_MAX_COUTNS = 5;
	static {
		MAJOR_LIST.add(new Major("0803Z100", "光电子技术基础"));
		MAJOR_LIST.add(new Major("08040000", "仪器科学与技术基础（大学物理）"));
		MAJOR_LIST.add(new Major("08310000", "医用电子学及微机应用"));
		MAJOR_LIST.add(new Major("08520200", "光电检测技术与图像传感器应用技术"));
		MAJOR_LIST.add(new Major("08520300", "仪器科学与技术基础（大学物理）"));
		MAJOR_LIST.add(new Major("08521614", "高分子化学与物理"));
		MAJOR_LIST.add(new Major("08520404", "无机材料专业基础"));
		MAJOR_LIST.add(new Major("02510000", "货币银行学"));
		MAJOR_LIST.add(new Major("08110300", "系统工程概论"));
		MAJOR_LIST.add(new Major("12040000", "管理学基础"));
		MAJOR_LIST.add(new Major("0801Z100", "力学综合复试（生物力学）"));
		MAJOR_LIST.add(new Major("08010300", "力学综合复试（流体力学）"));
		MAJOR_LIST.add(new Major("08020000", "机械工程综合考试（机械工程）"));
		MAJOR_LIST.add(new Major("0802J100", "机械工程综合考试（风能工程）"));
		MAJOR_LIST.add(new Major("08070200", "热传学（热能工程）"));
		

		for (Major major : MAJOR_LIST) {
			MAJOR_MAP.put(major.getMajorCode(), major);
		}

		STUDENT_LIST.add(new Student("张一", "100568000102001"));
		STUDENT_LIST.add(new Student("张二", "100568000102002"));
		STUDENT_LIST.add(new Student("张三", "100568000102003"));
		STUDENT_LIST.add(new Student("张四", "100568000102004"));
		STUDENT_LIST.add(new Student("张五", "100568000102005"));
		STUDENT_LIST.add(new Student("张六", "100568000102006"));
		STUDENT_LIST.add(new Student("张七", "100568000102007"));
		STUDENT_LIST.add(new Student("张八", "100568000102008"));
		STUDENT_LIST.add(new Student("张九", "100568000102009"));
		STUDENT_LIST.add(new Student("张十", "100568000102010"));
		STUDENT_LIST.add(new Student("张十一", "100568000102011"));
		STUDENT_LIST.add(new Student("张十二", "100568000102012"));
		STUDENT_LIST.add(new Student("张十三", "100568000102013"));
		STUDENT_LIST.add(new Student("张十四", "100568000102014"));
		STUDENT_LIST.add(new Student("张十五", "100568000102015"));
		STUDENT_LIST.add(new Student("张十六", "100568000102016"));
		STUDENT_LIST.add(new Student("张十七", "100568000102017"));
		STUDENT_LIST.add(new Student("张十八", "100568000102018"));
		STUDENT_LIST.add(new Student("张十九", "100568000102019"));
		STUDENT_LIST.add(new Student("张二十", "100568000102020"));
		STUDENT_LIST.add(new Student("张二十一", "100568000102021"));
		STUDENT_LIST.add(new Student("张二十二", "100568000102022"));
		STUDENT_LIST.add(new Student("张二十三", "100568000102023"));
		STUDENT_LIST.add(new Student("张二十四", "100568000102024"));
		STUDENT_LIST.add(new Student("张二十五", "100568000102025"));
		STUDENT_LIST.add(new Student("张二十六", "100568000102026"));
		STUDENT_LIST.add(new Student("张二十七", "100568000102027"));
		STUDENT_LIST.add(new Student("张二十八", "100568000102028"));

		for (Student student : STUDENT_LIST) {
			int majorCounts = (int) Math.ceil(Math.random() * STUDENT_MAX_COUTNS);
			List<Major> studentMajorList = new ArrayList<Major>();
			List<Major> tempMajorList = new LinkedList<Major>(MAJOR_LIST);
			for (int i = 0; i < majorCounts; i++) {
				int index = (int) Math.floor(Math.random() * tempMajorList.size());
				studentMajorList.add(tempMajorList.remove(index));
			}
			student.setMajorList(studentMajorList);
		}

		Map<String, List<Student>> temp = new TreeMap<String, List<Student>>(new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return o1.compareTo(o2);
			}
		});

		for (Student student : STUDENT_LIST) {
			for (Major major : student.getMajorList()) {
				if (temp.get(major.getMajorCode()) == null) {
					List<Student> studentList = new ArrayList<Student>();
					studentList.add(student);
					temp.put(major.getMajorCode(), studentList);
				} else {
					temp.get(major.getMajorCode()).add(student);
				}
			}
		}

		Set<Entry<String, List<Student>>> entrySet = temp.entrySet();
		for (Entry<String, List<Student>> e : entrySet) {
			Result r = new Result();
			r.setStudentList(e.getValue());
			r.setMajorCode(e.getKey());
			r.setMajorName(MAJOR_MAP.get(e.getKey()).getMajorName());
			RESULT_LIST.add(r);
		}
	}

	public static void main(String[] args) {

	}
}
